<style type="text/css">
#edit-matter-details h3{
  border:1px solid #4A7EBB;
  background:#93CDDD;
  color:#000;
  padding:10px;
  text-align:center;
  margin: 20px 40px;
}
#edit-matter-table{
  margin-left:20px;
}
#edit-matter-table th{
  text-align:right;
}
#edit-matter-table td{
  text-align:left;
  height:10px;
}
.head-tab{
  color: #1E4262;
  /*background-color: #1E4262;*/
  -moz-border-radius: 4px;
  -webkit-border-radius: 4px;
  border-radius: 4px;
  padding:5px 10px;
  border: 1px inset #CCC;
}

.row-tab{
  border:1px solid #888;
  background-color: #FFFFFF;
  -moz-border-radius: 4px;
  -webkit-border-radius: 4px;
  border-radius: 4px;
  padding:5px 10px;
  margin-top:5px;
  font-size: 10px;
}

.row-tab:hover {
  background-color: #AFB5C4 !important;
  cursor: pointer; 
}
.head-tab div{
  display:inline-block;
  /*font-size: 10px;*/
  font-weight: bold;
}

.row-tab div{
  display:inline-block;
  vertical-align:top;
  font-size: 10px;
/*  text-align: left; */
}

.column {
  margin: 0 10px 0px 0px;
  vertical-align:top;
}
.column-case{
  width:80px;
  text-align: left;
}
.column-title{
  width: 180px;
  text-align: left;
  vertical-align:middle;
}
.column-client{
  width: 70px;
  text-align:left;
}
.column-agent{
  width: 70px;
  text-align:left;
}
.column-client-ref{
  width: 80px;
  text-align:left;
  overflow-x: hidden;
  white-space: nowrap;
}
.column-agent-ref{
  width: 90px;
  text-align:left;
  overflow-x: hidden;
  white-space: nowrap;
}

.column-cat{
  width: 24px;
  text-align:left;
}
.column-status{
  width: 60px;
  text-align:left;
}
.column-date{
  width: 60px;
  text-align:left;
}

.column-inventor{
  width: 80px;
  text-align:left;
}

.column-filing-no{
  width: 70px;
  text-align:left;
  overflow-x: hidden;
  white-space: nowrap;
}
.column-pub-no{
  width: 75px;
  text-align:left;
  overflow-x: hidden;
  white-space: nowrap;
}

.column-ctnr-pri{
  width: 25px;
  text-align:center;
  vertical-align:middle;
  white-space: nowrap;
}

.sorting-dirs{
  /*color: white;
  font-size: 1em;
  padding: 1px 2px;*/
  cursor: pointer;
  /*vertical-align: center;*/
}

#matter-results-bg{
  width: 99%;
}
.filter-input{
  -moz-border-radius: 4px;
  -webkit-border-radius: 4px;
  border-radius: 4px;
  border: 1px inset #555;
  font-size: 9px;
  padding: 2px 1px;
}
.sorting-img{
    display: none;
    width: 11px;
    height: 9px;
    background: url('/images/sort-dirs.png') no-repeat;
}
#caseref-sort{
    background-position: 0px 0px;
    display: inline-block;
}
.matter-dead{
  color: #666;
  text-decoration: line-through;
}
</style>

<script type="text/javascript">
     var sortKey = "<?=$this->sort_id?>";
     var sortDir = "<?=$this->sort_dir?>";

function getFilterUrl()
{
         var ref = $('#filter-ref').val().replace(/\//,"~~");
         var cat = $('#filter-cat').val();
         var stat = $('#filter-status').val();
         var stat_date = $('#filter-status_date').val();
         var client = $('#filter-client').val();
         var clref = $('#filter-clref').val().replace(/\//,"~~");
         var agent = $('#filter-agent').val();
         var agtref = $('#filter-agtref').val().replace(/\//,"~~");
         var title = $('#filter-title').val().replace(/\//,"~~");
         var inventor = $('#filter-inventor').val();
         var filed = $('#filter-filed').val();
         var filno = $('#filter-filno').val().replace(/\//,"~~");
         var published = $('#filter-published').val();
         var pubno = $('#filter-pubno').val().replace(/\//,"~~");
         var granted = $('#filter-granted').val();
         var grtno = $('#filter-grtno').val().replace(/\//,"~~");
         
         var display_style = $('input:radio[name=displaystyle]:checked').val();
         var responsible = $('input[name=responsible-filter]:checked').val();

         var url = '';
         if($('input[name=container-filter]:checked').val() == 1){
            url = url + '/filter/Ctnr/value/1';
         }
         if(ref != '')
            url = url + '/Ref/'+ref;
         if(cat != '')
            url = url + '/Cat/'+cat;
         if(stat_date != '')
            url = url + '/Status_date/'+stat_date;
         if(stat != '')
            url = url + '/Status/'+stat;
         if(client != '')
            url = url + '/Client/'+client;
         if(clref != '')
            url = url + '/ClRef/'+clref;
         if(agent != '')
            url = url + '/Agent/'+agent;
         if(agtref != '')
            url = url + '/AgtRef/'+agtref;
         if(title != '')
            url = url + '/Title/%25'+title;
         if(inventor != '')
            url = url + '/Inventor1/'+inventor;
         if(filed != '')
            url = url + '/Filed/'+filed;
         if(filno != '')
            url = url + '/FilNo/'+filno;
         if(published != '')
            url = url + '/Published/'+published;
         if(pubno != '')
            url = url + '/PubNo/'+pubno;
         if(granted != '')
            url = url + '/Granted/'+granted;
         if(grtno != '')
            url = url + '/GrtNo/'+grtno;
         
        
         if(responsible == 1)
            url = url + '/responsible/'+'<?=$this->login?>';
         url = url + '/sort/'+sortKey+'/dir/'+sortDir;
         <?if($this->category_display){?>
            url = url + '/display/<?=$this->category_display?>';
         <?}?>
            url = url + '/display_style/'+display_style;
         //alert(url);
         return url;
}

$(document).ready(function(){
    <?if($this->display_style){?>
          	  $('.display_actor,.display_status').css('display','none');
              $('.display_status,').css('display','inline-block');
    <?}else {?>
              $('.display_actor,.display_status').css('display','none');
              $('.display_actor').css('display','inline-block');
    <?}?>


     if(sortDir == 'asc'){
         $('#'+sortKey+'-asc').attr('id', sortKey+"-desc");
         $('#'+sortKey+'-sort').css('background-position', '0px 0px');
     }else{
         $('#'+sortKey+'-sort').css('background-position', '-10px 0px');
     }
     $('.sorting-img').css('display', 'none');
     $('#'+sortKey+'-sort').css('display', 'inline-block');

     if(sortKey == ""){
         $('#caseref-sort').css('display', 'inline-block');
     }


     $(".linkcolumn").click(function(event){
        var id_array = $(this).attr('mid').split('-');
        var rid = $(this).attr('rid');
        var url = '/matter/view/id/'+id_array[2]+'/rid/'+rid;
        window.open(url);
     });


     $('.sorting-dirs').click(function(){
        var sort_id = $(this).attr('id').split('-');
        sortKey = sort_id[0];
        sortDir = sort_id[1];
        var url = '/matter/filter' + getFilterUrl();
        var objThis = $(this);
        var objSort = $('#'+sort_id[0]+'-sort');

        $.ajax({
             url: url,
             type: 'GET',
             data: { },
             success: function(data){
                 $('#matter-list').empty();
                 $('#matter-list').html(data);
                 if(sort_id[1] == 'asc'){
                      objThis.attr('id', sort_id[0]+"-desc");
                      objSort.css('background-position', "0px 0px");
                 }else{
                      objThis.attr('id', sort_id[0]+"-asc");
                      objSort.css('background-position', "-10px 0px");
                 }
                 $('.sorting-img').css('display', 'none');
                 objSort.css('display', 'inline-block');
                 window.history.pushState('', 'phpIP' , url);
             }
         });
     });


     $('.display_style').click(function(){

         if($(this).val() == 1){
             $('.display_actor,.display_status').css('display','none');
             $('.display_status,').css('display','inline-block');
             //Clear the filters exclusive to actor view
             $('#filter-agent').val('');
             $('#filter-agtref').val('');
             $('#filter-inventor').val('');
             $('#filter-filed').val('');
         }else {
             $('.display_actor,.display_status').css('display','none');
             $('.display_actor').css('display','inline-block');
             //Clear the filters exclusive to status view
             $('#filter-status_date').val('');
             $('#filter-filno').val('');
             $('#filter-published').val('');
             $('#filter-pubno').val('');
             $('#filter-granted').val('');
             $('#filter-grtno').val('');


         }

         var url = '/matter/filter' + getFilterUrl();
                  
         $.ajax({
             url: url,
             type: 'POST',
             data: {},
             success: function(data){
                 $('#matter-list').empty();
                 $('#matter-list').html(data);
                 window.history.pushState('', 'phpIP' , url);
             }
         });
     });


     $('#show-responsible').click(function(){
         var url = '/matter/filter' + getFilterUrl();
         $.ajax({
             url: url,
             type: 'GET',
             data: { },
             success: function(data){
                 $('#matter-list').empty();
                 $('#matter-list').html(data);
                 window.history.pushState('', 'phpIP' , url);
             }
         });
     });


     $('#show-containers').click(function(){
         var url = '/matter/filter' + getFilterUrl();
         $.ajax({
             url: url,
             type: 'GET',
             data: { },
             success: function(data){
                 $('#matter-list').empty();
                 $('#matter-list').html(data);
                 window.history.pushState('', 'phpIP' , url);
             }
         });
     });

     $('#show-all').click(function(){
         var url = '/matter/filter' + getFilterUrl();
         $.ajax({
             url: url,
             type: 'GET',
             data: { },
             success: function(data){
                 $('#matter-list').empty();
                 $('#matter-list').html(data);
                 window.history.pushState('', 'phpIP' , url);
             }
         });
     });

     $('.filter-input').keyup(function(){
         if($(this).val().length != 0 && $(this).val().length < 3 && ($(this).attr("id") == "filter-ref" || $(this).attr("id") == "filter-title")){
             return false;
         }
         var url = '/matter/filter' + getFilterUrl();;
         $.ajax({
             url: url,
             type: 'GET',
             data: { },
             success: function(data){
                 $('#matter-list').empty();
                 $('#matter-list').html(data);
                 window.history.pushState('', 'phpIP' , url);
             }
         });
     });
                  
     $('#clear-matter-filters').click(function(){
         $(location).attr('href', '/matter');
     });
                  
     $( "button, input:submit, input:button").button();
     $( "#container-all" ).buttonset();
     $( "#actor-status" ).buttonset();
     $( "#mine-all" ).buttonset();

});

</script> 

<div id="matter-results-bg" class="place-card">
<?php 
$show_conts = '';
$show_all = 'checked=checked';
if(isset($this->containers)){
    if($this->containers){
        $show_conts = 'checked=checked';
        $show_all = '';
    }
}
?>
<div id="container-all" style="float: left;">
  <input type="radio" id="show-all" name="container-filter" value=0 <?=$show_all?> />
  <label for="show-all" >Show All</label>
  <input type="radio" id="show-containers" name="container-filter" value=1 <?=$show_conts?> />
  <label for="show-containers" >Show Containers</label>
</div>


<div id="actor-status" style="float: left; margin-left: 20px;">
  <input class="display_style" type="radio" id="show-actor" name="displaystyle" value="0" <?if (!$this->display_style){?>checked<?}?>/>
  <label for="show-actor" >Actor View</label>
  <input class="display_style" type="radio" id="show-status" name="displaystyle" value="1" <?if ($this->display_style){?>checked<?}?>/>
  <label for="show-status" >Status View</label>
</div>

<div id="mine-all" style="float: left; margin-left: 20px;">
  <input class="responsible-filter" type="checkbox" id="show-responsible" name="responsible-filter" value="1" <?if ($this->responsible){?>checked<?}?>/>
  <label for="show-responsible" >Show Mine</label>
</div>

  <button id="clear-matter-filters" name="clear-filters" style="float: right;"><span class="ui-icon ui-icon-close" style="float: left;"></span> Clear filters</button>
<br><br>

<div class="head-tab">
<div  class="display_actor display_status column column-case"><a class="sorting-dirs" id="caseref-desc" >UID</a><span class="sorting-img" id="caseref-sort">&nbsp;</span><br>
<input type="text" name="filter-ref" id="filter-ref" value="<?=@$this->filters['Ref']?>" size=8 class="filter-input" />
</div>
<div class="display_actor display_status column column-cat">Cat
<br /><input type="text" name="filter-cat" id="filter-cat" value="<?=@$this->filters['Cat']?>" size=3 class="filter-input" /></div>
<div class="display_actor display_status column column-status"><a class="sorting-dirs" id="Status-asc">Status</a><span class="sorting-img" id="Status-sort">&nbsp;</span>
<br /><input type="text" name="filter-status" id="filter-status" value="<?=@$this->filters['Status']?>" size=8 class="filter-input" />
</div>
<div class="display_status column column-date"><a class="sorting-dirs" id="Status_date-asc">Date</a><span class="sorting-img" id="Status_date-sort">&nbsp;</span>
<br /><input type="text" name="filter-status_date" id="filter-status_date" value="<?=@$this->filters['Status_date']?>" size=8 class="filter-input" />
</div>
<div class="display_actor display_status column column-client"><a class="sorting-dirs" id="Client-asc">Client</a><span class="sorting-img" id="Client-sort">&nbsp;</span>
<br /><input type="text" name="filter-client" id="filter-client" value="<?=@$this->filters['Client']?>" size=8 class="filter-input" />
</div>
<div class="display_actor display_status column column-client-ref">Ref
<br /><input type="text" name="filter-clref" id="filter-clref" value="<?=@$this->filters['ClRef']?>" size=8 class="filter-input" />
</div>

<div class="display_actor column column-agent"><a class="sorting-dirs" id="Agent-asc">Agent</a><span class="sorting-img" id="Agent-sort">&nbsp;</span>
<br /><input type="text" name="filter-agent" id="filter-agent" value="<?=@$this->filters['Agent']?>" size=8 class="filter-input" />
</div>
<div class="display_actor column column-agent-ref">Ref
<br /><input type="text" name="filter-agtref" id="filter-agtref" value="<?=@$this->filters['AgtRef']?>" size=8 class="filter-input" />
</div>

<div class="display_actor column column-title">Detail
<br /><input type="text" name="filter-title" id="filter-title" value="<?=@$this->filters['Title']?>" size=16 class="filter-input" /></div>
                                                      
<div class="display_actor column column-inventor"><a class="sorting-dirs" id="Inventor1-asc">Inventor</a><span class="sorting-img" id="Inventor1-sort">&nbsp;</span>
<br /><input type="text" name="filter-inventor" id="filter-inventor" value="<?=@$this->filters['Inventor1']?>" size=8 class="filter-input" />
</div>
<div class="display_actor display_status column column-date"><a class="sorting-dirs" id="Filed-asc">Filed</a><span class="sorting-img" id="Filed-sort">&nbsp;</span>
<br /><input type="text" name="filter-filed" id="filter-filed" value="<?=@$this->filters['Filed']?>" size=8 class="filter-input" />
</div>
<div class="display_status column column-filing-no">Number
<br /><input type="text" name="filter-filno" id="filter-filno" value="<?=@$this->filters['FilNo']?>" size=8 class="filter-input" />
</div>

<div class="display_status column column-date"><a class="sorting-dirs" id="Published-asc">Published</a><span class="sorting-img" id="Published-sort">&nbsp;</span>
<br /><input type="text" name="filter-published" id="filter-published" value="<?=@$this->filters['filed']?>" size=8 class="filter-input" />
</div>
<div class="display_status column column-pub-no">Number
<br /><input type="text" name="filter-pubno" id="filter-pubno" value="<?=@$this->filters['PubNo']?>" size=8 class="filter-input" />
</div>


<div class="display_status column column-date"><a class="sorting-dirs" id="Granted-asc">Granted</a><span class="sorting-img" id="Granted-sort">&nbsp;</span>
<br /><input type="text" name="filter-granted" id="filter-granted" value="<?=@$this->filters['granted']?>" size=8 class="filter-input" />
</div>
<div class="display_status column column-pub-no">Number
<br /><input type="text" name="filter-grtno" id="filter-grtno" value="<?=@$this->filters['GrtNo']?>" size=8 class="filter-input" />
</div>

</div>

<div id="matter-list">
<?php if(count($this->paginator)):?>
<?php if(count($this->paginator) > 1)
   echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml');
?>

<?php 
$rindex = 0;

foreach($this->paginator as $matter):?>

<?php //print_r($matter);?>
<div class="row-tab" id="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex++?>" style="background: <?php echo ($matter['Ctnr'])?'lightcyan':'white'; ?>" >
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_actor display_status linkcolumn column column-case"><span class="<?php echo ($matter['dead'])?"matter-dead": "";?>"><?php echo $matter['Ref']; ?></span></div>
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_actor display_status linkcolumn column column-cat"><?php echo $matter['Cat']; ?></div>
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_actor display_status linkcolumn column column-status"><?php echo $matter['Status'];?></div>
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_status linkcolumn column column-date"><?php echo $matter['Status_date'];?></div>
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_actor display_status linkcolumn column column-client"><?php echo htmlentities($matter['Client']);?></div>
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_actor display_status linkcolumn column column-client-ref"><?php echo htmlentities($matter['ClRef']);?></div>
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_actor linkcolumn column column-agent"><?php echo htmlentities($matter['Agent']);?></div>
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_actor linkcolumn column column-agent-ref"><?php echo htmlentities($matter['AgtRef']);?></div>
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_actor linkcolumn column column-title"><?php echo htmlentities($matter['Title']);?></div>
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_actor linkcolumn column column-inventor"><?php echo htmlentities($matter['Inventor1']);?></div>
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_actor display_status linkcolumn column column-date"><?php echo $matter['Filed'];?></div>
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_status linkcolumn column column-filing-no" title="<?=$matter['FilNo']?>"><?php echo $matter['FilNo'];?></div>
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_status linkcolumn column column-date" title="<?=$matter['Published']?>"><?php echo $matter['Published'];?></div>
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_status column column-pub-no publink" title="<?=$matter['PubNo']?>" id="<?=$matter['country']."~".$matter['PubNo']?>"><?php
    if ($matter['origin'] == 'EP') $CC = 'EP';
    else $CC = $matter['country'];
    $country_code = $matter['country'];
    $removethese = array("/^$country_code/",'/ /', '/,/', '/-/', '/\//');
    $pubno = preg_replace($removethese, '', $matter['PubNo']);
    if ($CC == 'US') $pubno = substr($pubno, 0, 4) . substr($pubno, -6);
?>
<a href="http://worldwide.espacenet.com/publicationDetails/biblio?DB=EPODOC&CC=<?=$CC?>&NR=<?=$pubno?>" target="_blank"><?php echo $matter['PubNo'];?></a></div>
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_status linkcolumn column column-date" title="<?=$matter['Granted']?>"><?php echo $matter['Granted'];?></div>
<div mid="edit-matter-<?php echo $matter['ID'] ?>" rid="<?=$rindex?>" class="display_status linkcolumn column column-pub-no" title="<?=$matter['GrtNo']?>"><?php echo $matter['GrtNo'];?></div>

</div>

<?php endforeach; ?>
<?php if(count($this->paginator) > 1)
    echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml');
?>
<?php endif; ?>
</div>
</div>
